with open("trips.c", "w") as f:
    f.write('''\
/*
Tripcode cracker - Generates badass tripcodes.
Copyright (C) 2015 Anon and WireFi_hotspot.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/


//Includes
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <crypt.h>
#include <time.h>

//Defines
#define len(x) (sizeof(x) / sizeof(*(x)))

//Prototypes
char randCharRange(char lo, char hi);
char* generateString(size_t size);
char* generateTrip(char input[]);
char* findGems(char input[]);

//Body
char* generateTrip(char input[]) {
  char salt[2];
  char* ret;
  
  sprintf(salt, "%c%c", input[1], input[2]);
  ret = crypt(input, salt);
  
  *ret = &ret[strlen(ret) - 10];
}

char randCharRange(char lo, char hi) {
    return lo + (rand() % ((hi - lo) + 1));
}

char* generateString(size_t size) {
    char ret[64];
    
    for (int i = 0; i < size; i++) {
        ret[i] = randCharRange('A', 'Z');
    }
    
    ret[size] = 0;
    return ret;
}

#define GEMFILTER_I(x) if (strcasestr(input, x)) return x;
#define GEMFILTER_S(x) if (strstr(input, x)) return x;

char* findGems(char input[]) {
    //GEMFILTER_I("");
    //GEMFILTER_S("");
    
    GEMFILTER_S("GNU");
    GEMFILTER_S("RMS");
    
    GEMFILTER_I("Stallman");
    GEMFILTER_I("GNU/Linux");
    GEMFILTER_I("Linux");
    GEMFILTER_I("Gentoo");
    GEMFILTER_I("systemd");
    GEMFILTER_I("ReiserFS");
    GEMFILTER_I("Sadfrog");
    GEMFILTER_I("Feel");
    GEMFILTER_I("8chan");
    GEMFILTER_I("tech");
    
    return NULL;
}

void printTime()
{
    time_t current_time;
    char *text;
    
    current_time = time(NULL);
    text = ctime(&current_time);
    
    printf("%s\\n", text);
}
// That should do it
int main(void) {
    FILE *fp;
    time_t seedTime = time(NULL);
    int seedClock = clock();
    srand(seedTime % seedClock);
    
    char* password;
    char* tripcode;
    char* gem;
    char* format = "%s -> !%s (%s)\\n";
    long attempt = 0;
   
   printf("Starting on ");
   printTime();
   
   while(1) {
    fp = fopen("trips.txt", "a");
   if (fp == NULL){
    fprintf(stderr, "Error opening file\\n");
    return 1;
   }
    
        // generate random strings
        password = generateString(9); // I increased this to 9, so now it's slower.
        tripcode = generateTrip(password);
        gem = findGems(tripcode);
        
        if (gem) { // we found a match
            putchar('\\n');
            printf(     format, password, tripcode, gem);
            fprintf(fp, format, password, tripcode, gem);
        } else if (!(attempt % 500)) {
             putchar('.');
             fflush(stdout); // nice effect
        }
        
        attempt++;
        usleep(250);
        fclose(fp);
    }
    return EXIT_SUCCESS;
}
''')

#!Εр8рui8Vw2

#Anon, anon, anon! It's beautiful! We did it!
#Yes we did
# Virtual high-five
#*whap*!
# Now we just need a few more targets and we are officially open for business.
#It would be nice to have it so you can set whether or not a target is case-insensitive
# Hmmm.

import os, sys

def printLogo():
    print(
'''       ___       _         ___            _         __      
      / _ \     | |       / / |          | |       / /      
     | (_) | ___| |__    / /| |_ ___  ___| |__    / /       
      > _ < / __| '_ \  / / | __/ _ \/ __| '_ \  / /        
     | (_) | (__| | | |/ /  | ||  __/ (__| | | |/ /         
      \___/ \___|_| |_/_/    \__\___|\___|_| |_/_/          
                   _                                        
                  /  _  _| _ ._._  _. _|                    
                  \_(_)(_|(/_| |_)(_|(_|                    
                               |                            
           _______   _                     _                
          |__   __| (_)                   | |               
             | |_ __ _ _ __   ___ ___   __| | ___           
             | | '__| | '_ \ / __/ _ \ / _` |/ _ \          
             | | |  | | |_) | (_| (_) | (_| |  __/          
             |_|_|  |_| .__/ \___\___/ \__,_|\___|          
                      | |                                   
                      |_|                                   
             _____                _                         
            / ____|              | |                        
           | |     _ __ __ _  ___| | _____ _ __             
           | |    | '__/ _` |/ __| |/ / _ \ '__|            
           | |____| | | (_| | (__|   <  __/ |               
            \_____|_|  \__,_|\___|_|\_\___|_|               
                                                            
                                                            
''')

def build():
    print("Building")
    os.system("gcc trips.c -lcrypt -std=c11")
    os.system("mv a.out trips")

def run():
    if (not (os.path.isfile("./trips"))):
        build()
    printLogo();
    os.system("./trips")

build()
print("Enter 'run()' in the REPL to start")
